/**
 * <pre>
 * @(#)TestCase1.java 1.00 2009-11-25
 * 
 * Copyright (c) 1998, 2009 Regular Individual. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributor(s):
 *     Haixu Huang
 * </pre>
 **/
package _test_;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JScrollPane;

import cn.sh.huang.chart.MiniChart;
import cn.sh.huang.chart.config.TitleConfig;
import cn.sh.huang.chart.data.Argument;
import cn.sh.huang.chart.data.DataDecorator;
import cn.sh.huang.chart.data.DataSeries;
import cn.sh.huang.chart.data.DataTable;
import cn.sh.huang.chart.data.ext.ScalarNomalizer;
import cn.sh.huang.chart.view.ScalarView;
import cn.sh.huang.chart.view.View;
import cn.sh.huang.chart.view.container.LayoutView;

/**
 * <pre>
 * TestCase1 ...
 * 
 * @version 1.0
 * </pre>
 */
public class TestCase1 implements Runnable
{

    public void run()
    {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        MiniChart chart = new MiniChart();

        LayoutView layoutView = new LayoutView();
        TitleConfig config = layoutView.getTitleConfig();
        config.setTitle("Demo Chart View 0.01");
        config.setFont(new Font("Lucida Sans", Font.PLAIN, 36));

        View contentView = createChartView();
        layoutView.setContent(contentView);
        chart.setView(layoutView);

        JScrollPane pane = new JScrollPane();
        pane.setPreferredSize(new Dimension(640, 480));
        pane.setViewportView(chart);
        frame.getContentPane().add(pane);

        frame.pack();
        frame.setSize(new Dimension(640, 480));
        frame.setVisible(true);
    }

    private static View createChartView()
    {
        ScalarView chartView = new ScalarView();
        DataDecorator decorator = new DataDecorator() {

            public String toText(Object o)
            {
                return o.toString();
            }

            public Double toValue(Object o)
            {
                return (Double) o;
            }
        };

        Argument[] args = new Argument[10];
        for (int i = 0; i < args.length; i++) {
            final int _i = i;
            args[i] = new Argument() {
                private final String name = String.valueOf(_i);
                private final Double value = new Double(_i);

                public String getName()
                {
                    return name;
                }

                public Double getValue()
                {
                    return value;
                }
            };
        }

        DataSeries ser = new DataSeries("", decorator, new ScalarNomalizer());
        DataTable table = new DataTable(args);
        table.addSeries(ser, new Object[] { new Double(33), new Double(24), new Double(42), new Double(57),
                                           new Double(18), new Double(96), new Double(71), new Double(60),
                                           new Double(4), new Double(85) });
        chartView.setData(table);
        return chartView;
    }
}
